package com.quick.common.config.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.beans.BeanProperty;

@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String,Object>  redisTemplate = new RedisTemplate<>();
        // 为 Tempalte 设置连接工厂
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        // 设置 Key 的序列化方式
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        // 设置 Value 的序列化方式
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        // 设置默认序列化方式
        redisTemplate.setDefaultSerializer(new StringRedisSerializer());
        // 关键步骤：完成初始化
        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }
}